@if(Session::has('errors'))
<div id="panel-error" class="row">
	<div class="col-md-12">
		<div class="panel panel-red panel-minimal">
			<header class="panel-heading">{{trans('form.error')}}</header>
			<div class="panel-body">
				@foreach($errors as $error)
					{{$error['message']}} <br />
				@endforeach
			</div>
		</div>
	</div>
</div>
@endif

<div class='row'>
	<div class='col-md-12'>
		<div class="panel panel-default">
			<!--<header class="panel-heading">{{ trans('product.create') }}</header>-->
			<div class="panel-body">
				{{Form::open(array('method' => 'post', 'class' => 'form-horizontal', 'url' => 'admin/product/save', 'files' => true))}}
					<div class="form-group">
						{{Form::label('name', trans('product.productname'), array('class' => 'col-sm-2 control-label'))}}
						<div class="col-sm-5">
							{{Form::text('productname', Input::old('productname', (isset($product->name))? $product->name : null), array('class' => 'form-control', 'id' => 'group', 'placeholder' => trans('product.productname')))}}
						</div>
					</div>

					<div class="form-group">
						{{Form::label('alias', trans('product.alias'), array('class' => 'col-sm-2 control-label'))}}
						<div class="col-sm-5">
							{{Form::text('alias', Input::old('alias', (isset($product->alias))? $product->alias : null), array('class' => 'form-control', 'id' => 'alias', 'placeholder' => trans('product.alias')))}}
						</div>
					</div>

					<div class="form-group">
						{{Form::label('sku', trans('product.sku'), array('class' => 'col-sm-2 control-label'))}}
						<div class="col-sm-5">
							{{Form::text('sku', Input::old('sku', (isset($product->sku))? $product->sku : null), array('class' => 'form-control', 'id' => 'sku', 'placeholder' => trans('product.sku')))}}
						</div>
					</div>

					<div class="form-group">
						{{Form::label('price', trans('product.price'), array('class' => 'col-sm-2 control-label'))}}
						<div class="col-sm-5">
							{{Form::text('price', Input::old('price', (isset($product->price))? $product->price : null), array('class' => 'form-control', 'id' => 'price', 'placeholder' => trans('product.price')))}}
						</div>
					</div>

					<div class="form-group">
						{{Form::label('image', trans('product.image'), array('class' => 'col-sm-2 control-label'))}}
						<div class="col-sm-5">
							@if(isset($product->image))
								{{Form::image('/upload/product/' . $product->image, 'old_image_preview', array('id' => 'old_image_preview'))}}
							@endif
							{{Form::file('image')}}
						</div>
					</div>

					<div class="form-group">
						{{Form::label('brand', trans('product.brand'), array('class' => 'col-sm-2 control-label'))}}
						<div class="col-sm-5">
							{{Form::select('brand', $brand, (isset($product->brand))? $product->brand : null, array('class' => 'form-control', 'id' => 'brand'))}}
						</div>
					</div>

					<div class="form-group">
						{{Form::label('type', trans('product.type'), array('class' => 'col-sm-2 control-label'))}}
						<div class="col-sm-5">
							{{Form::select('type', $type, (isset($product->category))? $product->category : null, array('class' => 'form-control', 'id' => 'type'))}}
						</div>
					</div>

					<div class="form-group">
						{{Form::label('description', trans('product.description'), array('class' => 'col-sm-2 control-label'))}}
						<div class="col-sm-5">
							<div id="editor" style="height: 350px">
								{{Input::old('description', (isset($product->description))? $product->description : null)}}
							</div>
							{{Form::textarea('description', Input::old('description', (isset($product->description))? $product->description : null), array('style' => 'display: none;'))}}
						</div>
					</div>

					<div class="form-group">
						<div class="col-sm-2"></div>
						<div class="col-sm-5">
							{{Form::submit(trans('form.save'), array('class' => 'btn btn-primary btn-lg'))}}
							{{Form::button(trans('form.cancel'), array('class' => 'btn btn-default btn-lg', 'id' => 'cancel'))}}
						</div>
					</div>

					{{Form::hidden('id', (isset($product->id))? $product->id : 0, array('id' => 'id'))}}
					{{Form::hidden('old_image', (isset($product->image))? $product->image : 0, array('id' => 'old_image'))}}
				{{Form::close()}}
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
	$("button#cancel").click(function(event) {
		/* Act on the event */
		var url = '{{URL::to('admin/product/')}}';

		window.location = url;
	});

	$('form').submit(function(event) {
		/* Act on the event */
		var description = $('#editor').code();
		$("textarea[name='description']").val(description);
	});
});
</script>
<style type="text/css">
input#old_image_preview{
	height: 150px;
}
</style>